﻿using Microsoft.AspNetCore.Http;
using NPOI.SS.Formula.Functions;
using NPOI.SS.UserModel;
using Org.BouncyCastle.Asn1.Ocsp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace slwhTools.ExcelHelper
{
    /// <summary>
    /// 扩展方法类
    /// </summary>
    public static class SExcelExtensions
    {
        public static SExcelHelper<T> factory = new SExcelHelper<T>();
        public static ISExcel sexcel = new SExcel();


        public static IEnumerable<T> ReadExcel<T>(this MemoryStream? stream) where T : new()
        {
            return factory.ReadExcel<T>(stream);
        }

        public static IEnumerable<T> ReadExcelFile<T>(this IFormFile file) where T : new()
        {
            return factory.ReadExcelFile<T>(file);
        }

        public static void ImportExcel<T>(this IEnumerable<T> list) where T : new() 
        { 
            factory.ImportExcel<T>(list);
            return;
        }

        public static MemoryStream ImportExcelStream<T>(this IEnumerable<T> list) where T : new()
        {
            factory.ImportExcel<T>(list);
            return factory.RStream();
        }

        public static MemoryStream ImportExcelStream(this IWorkbook workbook)
        {   
            return factory.RStream();
        }
    }

    /// <summary>
    /// 自定义属性，用于指定 Excel 列名
    /// </summary>
    [AttributeUsage(AttributeTargets.Property)]
    public class SColumnAttribute : Attribute
    {
        public string Name { get; }

        public SColumnAttribute(string name)
        {
            Name = name;
        }
    }
}


